package com.mc.servlet;

import com.mc.bean.Match;
import com.mc.service.MatchService;
import com.mc.service.MatchStateService;
import com.mc.service.MatchTypeService;
import com.mc.service.impl.MatchServiceImpl;
import com.mc.service.impl.MatchStateServiceImpl;
import com.mc.service.impl.MatchTypeServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * @author zl
 * 赛事信息控制器
 */
@WebServlet("/matchlist.action")
public class MatchlistServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        MatchStateService matchStateService=new MatchStateServiceImpl();
        MatchTypeService matchTypeService=new MatchTypeServiceImpl();
        //创建业务逻辑对象
        MatchService matchService = new MatchServiceImpl();
        //将所有信息存放在集合中
        List<Match> list = matchService.findAll();
        req.setAttribute("matchStateService",matchStateService);
        req.setAttribute("matchTypeService",matchTypeService);
        //将集合中的信息放在request作用域中
        req.setAttribute("matchlist",list);
        //转发
        req.getRequestDispatcher("matchlist.jsp").forward(req,resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
